<{include file="simple_header.tpl"}>
<div class="content">
    <div class="upload">
        <div class="upload1">
            <div class="upname"> <h1> 上传图书 </h1> </div>
            <form id='upForm' method='post' action='/book/upload' enctype="multipart/form-data">
            <input type="hidden" name="MAX_FILE_SIZE" value="5242880">
            <div class="uplist" style="margin-top:30px;">
                <div class="uplistname"> <span> 上传图书: </span> </div>
                <div class="upvalue">
                    <div class="upinputs"> <input type="file" class="file" name="book_file"></div>
                </div>
            </div>
					<div class="uplist">
                    	<div class="uplistname"><span> 作者: </span></div>
                        <div class="upvalue"><div class="upinputw"><div class="upinputw1"><input type="text" class="textw" value="" name="author"></div></div>
                    </div> 
 
            <div class="uplist">
                <div class="uplistname"> <span> 图书名称: </span></div>
                <div class="upvalue">
                    <div class="upinput">
                        <div class="upinput1"><input type="text" class="text" value="" name="book_name" style="width:220px;"></div>
                    </div>
                </div>
			</div>
			
                <div style="display:none"><input type='hidden' name='selected_category_id' id='selected_category_id' value='0'></div>
                <div class="uplist">
                    <div class="uplistname"> <span> 图书分类: </span> </div>
                    <div class="upvalue">
                        <div class="upinputs" id='upinputs'>
                            <{section loop=$data name="ls" }>
                                <a href="javascript:void(0)" categoryid='<{$data[ls].id}>' title="<{$data[ls].name}>"> <{$data[ls].name}></a>
                                <{/section}>
                        </div>
                        <div class="am" id='createNewTagUI'>
                            <a href="javascript:void(0)" id='createBtn'> + 创建新分类 </a>
                        </div>
                        <div class="am" id='createNewTag' style='display:none'>
                            <div class="creat">
                                <input type="text" class="creats" value="" id='title'>
                                <a href="javascript:void(0)" id='realCreate'> 创建 </a>
                            </div>
                            <a href="javascript:void(0)" id='cancel' class="quxiao"> 取消 </a>
                        </div>
                    </div>
				</div>
                    <div class="uplist">
                        <div class="uplistname"><span>图书封面: </span></div>
                        <div class="upvalue"><div class="upinputs">
                        <input type="file" class="file" name="book_pic"></div></div>
                    </div>              
                    
                    <div class="uplist">
                        <div class="uplistname"><span>图书简介: </span></div>
                        <div class="upvalue"><div class="upinputi"><textarea class="introtext" name="book_desn"></textarea></div></div>
                    </div>

                    <div class="uplist">
                        <div class="uplistname"> </div>
                        <div class="upvalue"> <a href="javascript:void(0)" id='upSubmit' class="tijiao"> 点击提交 </a> </div>
                    </div>
					<div class="uplist">
                    	<div class="uplistname"></div>
                        <div class="upvalue"><span style='color:red'><{$message}></span></div>
                    </div> 
                </div>
            </div>
            </form>
        </div>
    </div>
</div>

<script>
$(function(){
    var default_category_id = $('#upinputs a').first().attr('categoryid');
    $('#selected_category_id').val(default_category_id);
    $('#upinputs a').first().attr('class','flnow');
    $('#createBtn').click(function(){
        $('#createNewTag').show();
        $('#createNewTagUI').hide();
    });
    $('#cancel').click(function(){
        $('#createNewTag').hide();
        $('#createNewTagUI').show();
    });
    $('#realCreate').click(function(){
        var title = $.trim($('#title').val());
        if(title==''){
            alert('请填写分类名称');
            return;
        }
        $.post('/category/new',{'categoryName':title},function(data){
            if(data.success){
                $('#upinputs a').attr('class','');
                $('#upinputs').append("<a href='javascript:void(0)' class='flnow' categoryid='"+data.data+"'>"+title+"</a>");
                $('#selected_category_id').val(data.data);
            }else{
                alert(data.message);
            }
        },'json');
    });
    $('#upinputs a').click(function(){
        $('#upinputs a').attr('class','');
        $(this).attr('class','flnow');
        $('#selected_category_id').val($(this).attr('categoryid'));
    });
	$('#upSubmit').click(function(){
		if($('#book_file').val()==''){
			alert('请选择图书');
			return;
		}
		$('#upForm').submit();
	});
});
</script>
<{include file="footer.tpl"}>
